<template>
	<view class="container">
		<view class="container--right">
			<uni-card :is-shadow="false">
				<text>欢迎登录</text>
			</uni-card>
		</view>
		<view class="container--right">
			<uni-section title="登录" type="line">
				<view class="login">
					<uni-forms>
						<!-- 账号-->
						<uni-forms-item label="账号" required="">
							<uni-easyinput type="number" v-model="loginFormData.stuId" placeholder="请输入账户"></uni-easyinput>
						</uni-forms-item>
						
						<!--类别-->
						<uni-forms-item label="密码" required="">
							<uni-easyinput type="password" v-model="loginFormData.stuPassword" placeholder="请输入密码"></uni-easyinput>
						</uni-forms-item>
						
						<!-- 账户类型-->
						<uni-forms-item label="登录类型" required="">
							<uni-data-checkbox v-model="loginFormData.type" :localdata="types"></uni-data-checkbox>
						</uni-forms-item>
					</uni-forms>
					<button size="mini" type="primary" form-type="submit" @click="login">提交</button>
					<button size="mini" type="warn" form-type="reset">重置</button>
				</view>
			</uni-section>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginFormData:{
					stuId:"",
					"stuPassword":"",
					"type":2
				},
			
				types:[
					{
						"text":"学生",
						"value":2
					},
					{
						"text":"管理员",
						"value":1
					},
					{
						"text":"超级管理员",
						"value":0
					}]
			}
			
		},
		methods: {
			login(){
				console.log(this.loginFormData.stuId)
				console.log(this.loginFormData.stuPassword)
				console.log(this.loginFormData.type)
				//提示正在登录
				uni.showToast({
					title:"正在登录",
					icon:'loading',
				})
				
				//根据不同的身份登录
				//1. 学生登录
				if(this.loginFormData.type===2){
					var _this=this
					uni.request({
						url:'http://localhost:9000/login',
						data:JSON.stringify(_this.loginFormData),
						method:'POST',
						dataType:'json',
						complete(res) {
							console.log(res)
							if(res.data===1){
								//学生登陆成功
								uni.showToast({
									title:"登陆成功",
									icon:'success'
								}),
								
								
								//跳转到个人信息页面
								uni.navigateTo({
									url:'../all_club/all_club',
									
								})
								
								
							}
						},
						
						//登陆失败
						fail() {
							uni.showToast({
								title:"登陆失败",
								icon:'error'
							})
						}
					})
				}
			}
		}
	}
</script>

<style>

</style>
